import 'package:flutter/material.dart';
import 'package:Sayagh/tablepress/csv.dart';
import 'package:Sayagh/i18n/i18nLocale.dart';
import 'package:Sayagh/Configs.dart';

class Essentials extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String essentialsUrl = "http://sayagh.asnafhormozgan.ir/wp-content/tables/essentionals.csv";
    Future<List<List>> essentialsList = csv(essentialsUrl);

    return Container(

//      appBar: AppBar(title: Text(i18nLocale[ourLocale]['essentials']),),
      child: FutureBuilder(
        future: essentialsList,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.data == null) {
            return Card(
              child: Text(i18nLocale[ourLocale]['reciving']),
            );
          }
          else {
            List<String> head = snapshot.data[0];
            return ListView.builder(
                itemCount: snapshot.data[1].length - 1,
                itemBuilder: (BuildContext context, int index) {
                  List<String> prices = snapshot.data[1][index];
                  
                  Color color = Colors.cyan;
                  if (index % 2 == 0) {
                    color = Colors.tealAccent;
                  }
                  String text = "";
                  for (int i = 0; i < head.length; i++) {
                    text = text + "\n" + head[i] + ":" + prices[i];
                  }

                  return Card(
                      color: color,
                      child: Text(text,textDirection: TextDirection.rtl,textAlign: TextAlign.center,)
                  );
                }
            );
          }
        },
      ),


    );
  }
}